app.controller("todayCtrl",function($scope,$ionicBackdrop,$timeout,$ionicModal,$state,$http,$ionicLoading){
    $scope.bookShow = true;
    $scope.examShow = true;
    $scope.noRead = false;
    $scope.hasRead = true;
    $scope.isNotice = true;
    //数据绑定
    var user_info = JSON.parse(localStorage.getItem("UserInfo"));

    // var getPath = JSON.parse(localStorage.getItem("getPath"));
    //用户数据
    angular.element(document).ready(function () {

        //用户名
        $scope.username = user_info.userName;
        //头像
        $scope.userHeader = user_info.userHeader;
        //组织
        if(user_info.orgSubName){
            $scope.orgSubName = "/"+user_info.orgSubName;
        }
        //职务
        if(user_info.positionName){
            $scope.positionName = "/"+user_info.positionName;
        }

        //平台
        $scope.orgName = user_info.orgName;
        //总阅读时间
        $scope.totalReadTime = user_info.totalReadTime || 0;
        //总阅读本数
        $scope.totalReadNum = user_info.totalReadNum || 0;
        //总阅读天数
        $scope.totalReadDay = user_info.totalReadDay || 0;


        //阅读顺序
        $scope.taskOrder = user_info.taskOrder;
        //书籍阅读中的总阅读天数
        $scope.nTotalTaskDate = user_info.nTotalTaskDate;
        //书名
        $scope.bookName = user_info.bookName;
        //图片
        if(user_info.bookImg){
            $scope.bookImg = imgPath.url+user_info.bookImg;
        }
        //出版社
        $scope.press = user_info.press;
        //通知数
        $scope.getNoticeCnt();
        //阅读计划和考试计划都不存在
        if(!user_info.bCircleExist && !user_info.bExamExist){
            $scope.bookShow = false;
            $scope.examShow = false;
            $scope.noRead = true;
        }else{
            // //阅读
            if(!user_info.bCircleExist){
                $scope.bookShow = false;
            }else{
                //获取阅读信息
                $scope.getTotalReadCycle();
            }
            //考试
            if(!user_info.bExamExist){
                //获取考试信息
                $scope.examShow = false;
            }
        }
        // if(!true && !false){
        //     $scope.bookShow = false;
        //     $scope.examShow = false;
        //     $scope.noRead = true;
        // }else{
        //     //阅读
        //     if(true){
        //         //获取阅读信息
        //         $scope.getTotalReadCycle();
        //     }else{
        //         $scope.bookShow = false;
        //     }
        //     //考试
        //     if(false){
        //         //获取考试信息
        //         $scope.examShow = false;
        //     }
        // }
    });
    //获取通知数
    $scope.getNoticeCnt = function () {
        var url = getPath.url+getPath.name+"/app/getNoticeCnt";
        var param = {
            userId:user_info.userId
        }
        $http({
            url: url,
            method: "POST",
            data:param,
            headers:{'Content-Type':'application/x-www-form-urlencoded'}
        }).success(function(data){
                var res = data.resultBean;
                if(data.resultCode==200){
                    //通知数
                    if(res==0){
                        // $scope.nNoticeCnt = "";
                        $scope.isNotice = false;
                    }else{
                        $scope.nNoticeCnt = res;
                    }
                }else{
                    $ionicLoading.show({
                        template: data.result,
                        duration:3000
                    });
                }
            })
            .error(function(data){
                $ionicLoading.show({
                    template: data.result,
                    duration:3000
                });
            });
    }
    //获取阅读信息
    $scope.getTotalReadCycle = function () {
        var url = getPath.url+getPath.name+"/app/getTotalReadCycle";
        var param = {
            userId:user_info.userId
        }
        $http({
            url: url,
            method: "POST",
            data:param,
            headers:{'Content-Type':'application/x-www-form-urlencoded'}
        }).success(function(data){
                var res = data.resultBean;
                if(data.resultCode==200){
                    //总阅读时间
                    $scope.totalReadTime = res.totalReadTime || 0;
                    //总阅读本数
                    $scope.totalReadNum = res.totalReadNum || 0;
                    //总阅读天数
                    $scope.totalReadDay = res.totalReadDay || 0;
                }else{
                    $ionicLoading.show({
                        template: data.result,
                        duration:3000
                    });
                }
            })
            .error(function(data){
                $ionicLoading.show({
                    template: data.result,
                    duration:3000
                });
            });
    }
    //阅读
    $scope.openCover = function(){
        $state.go("home.read-cover");
    };
    //打开通知
    $scope.openNotice = function(){
        $state.go("home.inform-page");
    };
    //设置
    $scope.openSetting = function(){
        $state.go("home.mySetting");
    }
    //考试
    $scope.openExamList = function () {
        $state.go("home.examList");
    }
});